<?php
include("code/databaseconnection.php");

include("header.php");
?>

<?php

if($_GET['action']=="delete")
{
	$id=$_GET['id'];
	mysql_query("DELETE FROM workshop
 WHERE ID='".$id."'") or die(mysql_error());	
	echo '<font color="#FF0000" size="6" >User id  '.$id.' Deleted</font>';
}
?>
<?php

if($_GET['action']=="edit")
{
	$id=$_GET['id'];
	$rowresult=mysql_query("SELECT * FROM workshop WHERE ID='".$id."'  ") or die(mysql_error());
	
		$row=mysql_fetch_array($rowresult);
		$g_title = $row['TITLE'];
		$g_subject = $row['SUBJECT'];
		$g_subject_year = $row['SUBJECT_YEAR'];
		$g_num_of_days = $row['NUM_OF_DAYS'];
		$g_start_date =  $row['START_DATE'];
		$g_end_date = $row['END_DATE'];
		$g_venue = $row['VENUE'];
		$g_num_of_participant = $row['NUM_OF_PARTICIPANT'];
		$g_num_of_resource = $row['NUM_OF_RESOURCE'];
		$g_limit = $row['LIMIT'];
		$g_conducting_agency = $row['CONDUCTING_AGENCY'];
		$g_vote_num = $row['VOTE_NUM'];
		$g_funding =  $row['FUNDING'];
		$g_source = $row['SOURCE'];
		$g_estimate_cost = $row['ESTIMATE_COST'];
		$g_actual_cost = $row['ACTUAL_COST'];
		$g_id_number = $row['ID_NUMBER'];
		
?>
<form action="workshop_manage.php?action=update&id=<?php  echo $id; ?>" method="post">
<table width="600" cellspacing="0" cellpadding="0">
    <tr>
      <td width="199">Title:</td>
      <td width="399"><input type="text" name="title" size="30"  value="<?php echo $g_title; ?>" /></td>
    </tr>
    
    <tr>
    <td>Subject:</td>
      <td><input type="text" name="subject" size="30" value="<?php echo  $g_subject; ?>" /></td>
    </tr>
  
    
    <tr>
      <td>Start Date</td>
      <td><input type="text" name="start_date" size="30" value="<?php echo $g_start_date; ?>" /></td>
    </tr>
    
    <tr>
      <td>End Date</td>
      <td><input type="text" name="end_date" size="30" value="<?php echo $g_end_date; ?>" /></td>
    </tr>
    
    <tr>
      <td>Venue</td>
      <td><input type="text" name="venue" size="30" value="<?php echo $g_venue; ?>" /></td>
    </tr>
    
    <tr>
      <td>Num Of Participant</td>
      <td><input type="text" name="num_of_participant" size="30" value="<?php echo  $g_num_of_participant; ?>"  /></td>
    </tr>
    
    
    <tr>
      <td width="199">Subject Year:</td>
      <td width="399"><select name="subject_year" style="width: 215px">
      <option value=' <?php $g_subject_year ?>'><?php echo $g_subject_year; ?></option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="4">9</option>
      <option value="5">10</option>
      <option value="O/L">O/L</option>
      <option value="A/L">A/L</option>
      </select>	
    </td>
    </tr>
   
    <tr>
      <td width="199">Numer of days:</td>
      <td width="399"><select name="num_of_days" style="width: 215px">
      <option value=' <?php $g_num_of_days ?>'><?php echo $g_num_of_days; ?></option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      </select>	
    </td>
    </tr>
  
  <tr>
      <td width="199">Num Of Resource</td>
      <td width="399"><input type="text" name="num_of_resource" size="30" value="<?php echo  $g_num_of_resource; ?>" /></td>
    </tr>
    
    <tr>
    <td>Limit</td>
      <td><input type="text" name="limits" size="30" value="<?php echo  $g_limits; ?>" /></td>
    </tr>
    

    
    <tr>
      <td>Conducting Agency</td>
      <td><input type="text" name="conducting_agency" value="<?php echo  $g_conducting_agency ; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>Vote Number</td>
      <td><input type="text" name="vote_num" value="<?php echo  $g_vote_num; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>Funding</td>
      <td><input type="text" name="funding" value="<?php echo  $g_funding; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>Source</td>
      <td><input type="text" name="source" value="<?php echo  $g_source; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>Estimate Cost</td>
      <td><input type="text" name="estimate_cost" value="<?php echo  $g_estimate_cost; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>Actual Cost</td>
      <td><input type="text" name="actual_cost" value="<?php echo  $g_actual_cost; ?> " size="30" /></td>
    </tr>
    
    <tr>
      <td>ID Number</td>
      <td><input type="text" name="id_number" value="<?php echo  $g_id_number; ?> " size="30" /></td>
    </tr>
    
    
  
  <tr>
    <td></td>
    <td> <input type="submit" name="submit" value="update" ></td>
  </tr>
  
</table>
</form>

<?php
}

if($_GET['action']=="update")
{
	$id=$_GET['id'];
	$g_title=$_POST['title'];
	$g_subject =$_POST['subject'];
	$g_subject_year =$_POST['subject_year'];
	$g_start_date=$_POST['start_date'];
	$g_end_date=$_POST['end_date'];
	$g_venue=$_POST['venue'];
	$g_num_of_participant=$_POST['num_of_participant'];
	$g_num_of_days=$_POST['num_of_days'];
	$g_num_of_resource=$_POST['num_of_resource'];
	$g_limits=$_POST['limit'];
	$g_conducting_agency=$_POST['conducting_agency'];
	$g_vote_num=$_POST['vote_num'];
	$g_funding=$_POST['funding'];
	$g_source=$_POST['source'];
	$g_estimate_cost=$_POST['estimate_cost'];
	$g_actual_cost=$_POST['actual_cost'];
	$g_id_number=$_POST['id_number'];
	 
mysql_query("UPDATE workshop SET 'TITLES'='".$g_titles."','SUBJECT'='".$g_subject."','SUBJECT_YEAR'='".$g_subject_year."','NUM_OF_DAYS'='".$g_num_of_days."','START_DATE'='".$g_start_date."','END_DATE'='".$g_end_date."','VENUE'='".$g_venue."',NUM_OF_PARTICIPANT='".$g_num_of_participant."',NUM_OF_RESOURCE='".$g_num_of_resource."',LIMITS='".$g_limits."',CONDUCTING_AGENCY='".$g_conducting_agency."',VOTE_NUM='".$g_vote_num."',FUNDING='".$g_funding."',SOURCE='".$g_source."',ESTIMATE_COST='".$g_estimate_cost."',ACTUAL_COST='".$g_actual_cost."',ID_NUMBER='".$g_id_number."'   WHERE ID='".$id."'  ") or die(mysql_error());
	
	echo '<font color="#009900" size="6" >User id  '.$id.' Updated</font>';
}

if($_GET['action']=="")
{
$result=mysql_query("SELECT * FROM workshop ");
$total = mysql_num_rows($result);
$i=0;

echo '<table width="600" border="1"> 
<tr><td>TITLE</td>
	<td>SUBJECT</td>
    <td>SUBJECT_YEAR</td>
    <td>NUM_OF_DAYS</td>
    <td>START_DATE</td>
    <td>END_DATE</td>
    <td>VENUE</td>
    <td>NUM_OF_PARTICIPANT</td>
    <td>NUM_OF_RESOURCE</td>
    <td>LIMITS</td>
	<td>CONDUCTING_AGENCY</td>
	<td>VOTE_NUM</td>
	<tr>
	<td>FUNDING</td>
	<td>SOURCE</td>
    <td>ESTIMATE_COST</td>
    <td>ACTUAL_COST</td>
    <td>ID_NUMBER</td>
    <td>Edit</td>
	<td>Delete</td>
</tr>';
	while ($i < $total)
	{
		$row=mysql_fetch_array($result);
		$g_title = $row['TITLE'];
		$g_subject = $row['SUBJECT'];
		$g_subject_year = $row['SUBJECT_YEAR'];
		$g_num_of_days= $row['NUM_OF_DAYS'];
		$g_start_date =  $row['START_DATE'];
		$g_end_date = $row['END_DATE'];
		$g_id_number = $row['VENUE'];
		$g_num_of_participant = $row['NUM_OF_PARTICIPANT'];
		$g_num_of_resource = $row['NUM_OF_RESOURCE'];
		$g_limits = $row['LIMITS'];
		$g_conducting_agency = $row['CONDUCTING_AGENCY'];
		$g_vote_num = $row['VOTE_NUM'];
		$g_funding= $row['FUNDING'];
		$g_source = $row['SOURCE'];
		$g_estimate_cost =  $row['ESTIMATE_COST'];
		$g_actual_cost = $row['ACTUAL_COST'];
		$g_id_number = $row['ID_NUMBER'];
		$g_id = $row['ID'];
		
		echo "
		<tr>
	<td>".$g_title."</td>
	<td>".$g_subject."</td>
    <td>".$g_subject_year."</td>
    <td>".$g_num_of_days."</td>
    <td>".$g_start_date."</td>
    <td>".$g_end_date."</td>
    <td>".$g_id_number."</td>
    <td>".$g_num_of_participant."</td>
    <td>".$g_num_of_resource."</td>
    <td>".$g_limits."</td>
	<td>".$g_conducting_agency."</td>
    <td>".$g_vote_num."</td>
    <td>".$g_funding."</td>
    <td>".$g_source."</td>
    <td>".$g_estimate_cost."</td>
    <td>".$g_actual_cost."</td>
    <td>".$g_id_number."</td>
       
	 <td>
	 <a href='?action=delete&id=".$row['ID']."' >
	 <img src='delete.png' border='0' />
	 </a>
	 </td>
	<td><a href='?action=edit&id=".$row['ID']."' ><img border=0 src='edit.png' /></a>
	</td>
</tr>";
		
		
		//echo "<option value='".$row['name']."'>".$row['name']."</option>";
		$i++;
		
	}
	echo "</table>";
}
	
?>
<?php 
include("fooder.php");
?>